<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { bluetoothManager } from "./utils";
function randomString28() {
  const chars =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  let result = "";
  for (let i = 0; i < 28; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  return result;
}

onLaunch(() => {
  console.log("Smart Door Lock App Launch");
  bluetoothManager.onBluetoothAdapterStateChange((res) => {
    console.log(res, "res");
    if (!res.available) {
      uni.reLaunch({
        url: "/pages/search-device/search-device",
        success: () => {
          setTimeout(() => {
            uni.showToast({
              title: "蓝牙不可用",
              icon: "none",
            });
          }, 1000);
        },
      });
    }
  });
  // 初始化应用状态
  uni.setStorageSync("appVersion", {
    firmware: "V1.0.1",
    software: "V1.0.2",
  });
  uni.getStorage({
    key: "openId",
    fail: () => {
      uni.setStorageSync("openId", randomString28());
    },
    success: (res) => {
      console.log(res, "res");
    },
  });
});

onShow(() => {
  console.log("Smart Door Lock App Show");
});

onHide(() => {
  console.log("Smart Door Lock App Hide");
});
</script>

<style>
/* 引入安全距离样式 */
@import "./styles/safe-area.css";

/* 全局样式 */
page {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans",
    Helvetica, Arial, sans-serif;
  line-height: 1.5;
  height: 100%;
  /* 支持安全区域 */
  viewport-fit: cover;
}

/* 全局变量 */
:root {
  --primary-color: #2c3045;
  --secondary-color: #ecedf4;
  --background-gradient: linear-gradient(to bottom, #e6ebff, #f8faff, #ffffff);
  --text-color: #2c3045;
  --text-light: #666;
  --border-color: #ddd;
  --shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 8rpx 16rpx rgba(0, 0, 0, 0.15);
}

/* 通用按钮样式 */
.btn-primary {
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 24rpx;
  font-weight: 500;
  transition: all 0.3s ease;
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: var(--text-color);
  border: none;
  border-radius: 24rpx;
  font-weight: 500;
  transition: all 0.3s ease;
}

.btn-outline {
  background-color: transparent;
  color: var(--text-light);
  border: 2rpx solid var(--border-color);
  border-radius: 24rpx;
  font-weight: 500;
  transition: all 0.3s ease;
}

/* 通用卡片样式 */
.card {
  background-color: var(--secondary-color);
  border-radius: 24rpx;
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

/* 通用标题样式 */
.title-primary {
  color: var(--text-color);
  font-weight: bold;
}

.title-secondary {
  color: var(--text-light);
}

/* 动画类 */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

.slide-up {
  animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(20rpx);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 响应式布局 */
@media screen and (max-width: 750rpx) {
  .responsive-padding {
    padding: 32rpx !important;
  }

  .responsive-font {
    font-size: 28rpx !important;
  }
}
</style>
